/*
NoBuffer Notepad Copyright (C) 2015  Mahmoud Jaoune

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFile>
#include <QString>
#include <QByteArray>
#include <QTextStream>
#include <QFileInfo>
#include <QResizeEvent>
#include <QMessageBox>
#include <QFileDialog>
#include "ui_mainwindow.h"
#include "textedit.h"
#include "notifwidget.h"
#include "blockdb.h"
#include "aboutdialog.h"
#include "settingsdialog.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void loadFile(const char *fileName);
    void resizeEvent(QResizeEvent *event);

    QMap<QString, BlockDB> blockDB;
    NBN_ProgressWidget * fileReadProgressGUI;

private:
    Ui::MainWindow *ui;

private slots:
    void NBN_setProgress(unsigned int progress, unsigned int total);
    void NBN_endProgressGUI();
    void NBN_SetTotalBlocks(int nBlocks, QString currentTab);
    void on_goBlock_clicked();
    void on_mainWidget_currentChanged(int index);
    void on_mainWidget_tabCloseRequested(int index);

    /* MenuBar actions */
    void on_NewAction();
    void on_OpenAction();
    void on_SaveAction();
    void on_SaveAsAction();
    void on_ExitAction();

    void on_UndoAction();
    void on_RedoAction();
    void on_CutAction();
    void on_CopyAction();
    void on_PasteAction();

    void on_SettingsAction();
    void on_AboutAction();
    /* End of MenuBar actions */

    void sendReloadSettings();

    void on_backBlock_clicked();

    void on_nextBlock_clicked();

signals:
    void NBN_OnSelectBlock(unsigned int block, NBN_TextEdit* currentTextEdit);
    void WindowResized(int width, int height);
    void reloadSettings();
    void NBN_CleanThread(QString currentTab);

    /* MenuBar related */
    void NBN_SendSave(QString currentTab, BlockDB database);
    void NBN_SendSaveAs(QString currentTab, QString newFileName, BlockDB database);

    void NBN_SendUndo(QString currentTab);
    void NBN_SendRedo(QString currentTab);
    void NBN_SendCut(QString currentTab);
    void NBN_SendCopy(QString currentTab);
    void NBN_SendPaste(QString currentTab);
};

#endif // MAINWINDOW_H
